import pandas as pd
import numpy as np
from IPython.display import display
df = pd.read_csv(r"D:\WXWork\1688856846627697\Cache\File\2025-10\phones.csv", header=None, encoding='gbk')
print(df.head())
print('\n')

json_date=pd.read_json(r"D:\WXWork\fruits.json",encoding='UTF-8')
print(json_date.head())
print('\n')

df1=pd.DataFrame([['李明','m','11','beijing'],
                  ['zhanghua','m','12','tianjin'],
                  ['liutao','f','118','shanghai'],
                  ['liuto','f','20','shenzhen'],
                  ['wangfeng','f','19','henan']],
                 index=['one', 'two', 'three', 'four','five'],
                    columns=['name','gender','age','city'])
df1['age']=pd.to_numeric(df1['age'])

data=df1[['name']][:3]
print('访问name列前3行的数据：',data)
display(data)

data=df1[['name','age']][:3]
print('访问name列和age列前3行的数据：')
display(data)

data=df1[1:3]
print('访问第1-2行的数据：')
display(data)

data=df1.iloc[:,:3][df1['age']>18]
print('选取年龄大于18的\n',data)
display(data)

